<?php
	require_once '/usr/share/php/PHPUnit/Framework.php'; 
	require_once("/usr/share/php/Zend/Loader.php");
	Zend_Loader::registerAutoLoad();

	# determine location in file system
	exec('pwd', $pwd_full);
	$pwd_parts = explode('/', $pwd_full[0]);
	$subdomain = $pwd_parts[sizeof($pwd_parts) - 2];
	
	# determine unit test config
	$path = $pwd_full[0];
	if ($subdomain == 'modavid' || $subdomain == 'jobloggin')
	{
		$path .= "/..";
		$config_settings = $subdomain . '-unit-test';
	}
	else
	{
		$path = "/var/www/mobloggin-latest-build";
		$config_settings = 'unit-test';
	}

	# set up unit test config file
	$config = new Zend_Config_Ini("$path/config/settings.ini", 
		$config_settings, $options);
	Zend_Registry::set('config', $config);

	# build an include path similar to that in httpd.conf
	set_include_path(get_include_path() . PATH_SEPARATOR 
		. $config->path->include->dir . PATH_SEPARATOR
		. $config->path->lib->dir . PATH_SEPARATOR
		. $config->path->zend->dir . PATH_SEPARATOR
		. $config->path->unit_tests->models->dir . PATH_SEPARATOR
		. $config->path->unit_tests->sdbmanagers->dir);
	
	# model test suite
	class MoblogginTestSuite extends PHPUnit_Framework_TestSuite
	{
		# set tests to run when this suite is executed
		public static function suite()
		{
			$suite = new MoblogginTestSuite();
			
			# misc
			$suite->addTestSuite('CommonGeneratorTest');

			# test models
			$suite->addTestSuite('S3andSDBModelTest');
			$suite->addTestSuite('CommentTest');
			$suite->addTestSuite('MediaTest');
			$suite->addTestSuite('FollowingTest');
			$suite->addTestSuite('RelationshipTest');
			$suite->addTestSuite('TagTest');
			$suite->addTestSuite('ThumbnailTest');
			$suite->addTestSuite('UserTest');
			
			# test SDBManagers
			$suite->addTestSuite('SDBManagerTest');
			$suite->addTestSuite('CommentSDBManagerTest');
			$suite->addTestSuite('MediaSDBManagerTest');
			$suite->addTestSuite('FollowingSDBManagerTest');
			$suite->addTestSuite('RelationshipSDBManagerTest');
			$suite->addTestSuite('TagSDBManagerTest');
			$suite->addTestSuite('ThumbnailSDBManagerTest');
			$suite->addTestSuite('UserSDBManagerTest');
		
			return $suite;
		}

		protected function setUp()
		{
			# get global config file
			$config = Zend_Registry::get('config');

			# set up unit test logger
			$mode = (file_exists($config->path->logs->general->file)) ? 'a' : 'w';
			$logger = new Zend_Log(new Zend_Log_Writer_Stream(
				$config->path->logs->general->file), $mode);

			# get amazon keys
			$aws_public = exec('getawskey public');
			$aws_private = exec('getawskey private');

			# create simpledb interaction object and store it in the registry
			$sdb = new SDB($aws_public, $aws_private);

			# create s3 interaction object and store it in the registry
			$s3 = new S3($aws_public, $aws_private);

			# save to registry for later use
			Zend_Registry::set('s3', $s3);
			Zend_Registry::set('sdb', $sdb);
			Zend_Registry::set('logger', $logger);
		}     

		protected function tearDown() { }
	}
